import tkinter as tk

root = tk.Tk()
root.title("Grid Parameters Example")

# 创建一个Frame作为面板
frame = tk.Frame(root, bg="light gray", padx=10, pady=10)
frame.grid(row=0, column=0, sticky="nsew")

# 创建几个Label，每个Label展示不同的grid参数效果
label1 = tk.Label(frame, text="Label 1", bg="red", fg="white")
label1.grid(row=0, column=0, padx=5, pady=5)

label2 = tk.Label(frame, text="Label 2", bg="green", fg="white")
label2.grid(row=1, column=0, sticky="ew", padx=5, pady=5)

label3 = tk.Label(frame, text="Label 3", bg="blue", fg="white")
label3.grid(row=2, column=0, rowspan=2, padx=5, pady=5, sticky="nsew")

label4 = tk.Label(frame, text="Label 4", bg="orange", fg="white")
label4.grid(row=0, column=1, columnspan=2, padx=5, pady=5, sticky="nsew")

label5 = tk.Label(frame, text="Label 5", bg="purple", fg="white")
label5.grid(row=1, column=1, padx=5, pady=5, sticky="nsew")

button = tk.Button(frame, text="Button", bg="gray", fg="white")
button.grid(row=1, column=2, padx=5, pady=5, sticky="nsew")

# 配置面板的行和列权重，使其能够扩展
frame.grid_rowconfigure(0, weight=1)
frame.grid_rowconfigure(1, weight=1)
frame.grid_rowconfigure(2, weight=1)
frame.grid_columnconfigure(0, weight=1)
frame.grid_columnconfigure(1, weight=1)
frame.grid_columnconfigure(2, weight=1)

root.mainloop()
